import { PiniaPluginContext } from "pinia";

export function persistedState (context:PiniaPluginContext) {
	const currentState = JSON.parse(wx.getStorageSync(context.store.$id)||"{}")
	context.store.$patch(currentState)
	context.store.$subscribe((_store,state)=>{
		wx.setStorage({
					key:_store.storeId,
					data:JSON.stringify(state)
				})
	},
	{
		detached:true
	})
}